package com.kwan.x_im.data.http;


import com.kwan.xframe.mvvm.data.source.http.BaseHttpDataSource;
import com.kwan.xframe.mvvm.data.source.http.HttpResult;
import com.kwan.xframe.mvvm.data.source.http.HttpRetrofitClient;

import java.util.HashMap;
import java.util.TreeMap;

import io.reactivex.rxjava3.core.Flowable;

import static com.kwan.xframe.mvvm.BaseTokenManager.sToken;

public class HttpDataSource extends BaseHttpDataSource {


	public HttpRetrofitClient mApiClient;

	public ApiService mApiService;

	public static final String API_URL = "http://8.217.117.105:13851";

	public HttpDataSource() {
		HashMap<String, String> head = HttpRetrofitClient.createCommonHeader();
		head.put("Authorization", "Bearer " + sToken);
		mApiClient = getHttpRetrofitClient(API_URL, head);
		mApiService = mApiClient.create(ApiService.class);
	}


	public Flowable<HttpResult<Object>> checkToken(String idToken) {
		TreeMap<String, Object> params = new TreeMap<>();
		params.put("idToken", idToken);
		return mApiService.checkToken(params);
	}

	public Flowable<HttpResult<Object>> refreshToken() {
		return mApiService.refreshToken();
	}



	public Flowable<HttpResult<Object>> orderSn(String googleUserId, String productId) {
		TreeMap<String, Object> params = new TreeMap<>();
		params.put("googleUserId", googleUserId);
		params.put("productId", productId);
		return mApiService.orderSn(params);
	}

	public Flowable<HttpResult<Object>> verifyOrder(String jsonData) {
		TreeMap<String, Object> params = new TreeMap<>();
		params.put("jsonData", jsonData);
		return mApiService.verifyOrder(params);
	}

	public Flowable<HttpResult<Object>> purchaseChapter(String googleUserId, String novelId, String chapterIds) {
		TreeMap<String, Object> params = new TreeMap<>();
		params.put("googleUserId", googleUserId);
		params.put("novelId", novelId);
		params.put("species", 1);
		params.put("chapterIds", chapterIds);
		return mApiService.purchaseChapter(params);
	}








	public Flowable<HttpResult<Object>> addLibrary(String googleUserId, String novelId) {
		TreeMap<String, Object> params = new TreeMap<>();
		params.put("googleUserId", googleUserId);
		params.put("novelCode", novelId);
		return mApiService.addLibrary(params);
	}

}
